package org.nlp2rdf.navigator.junit;

import java.util.List;

import org.apache.log4j.Logger;
import org.junit.Test;
import org.nlp2rdf.navigator.api.KnowledgeBase;
import org.nlp2rdf.navigator.client.common.ExampleDTO;
import org.nlp2rdf.navigator.client.common.SearchResultDTO;
import org.nlp2rdf.navigator.component.search.ISearch;
import org.nlp2rdf.navigator.server.WorkerServletWrapper;
import org.nlp2rdf.navigator.util.LogHelper;
import org.springframework.context.ApplicationContext;

public class Util {
	@SuppressWarnings("unused")
	private static final Logger logger = Logger.getLogger(Util.class);
	static String loggers = LogHelper.touch();
	static ApplicationContext context = init();

	// turn these to null for testing
	static KnowledgeBase tiger = KnowledgeBase.getInstance(context, "tiger");
	static KnowledgeBase dbpedia = KnowledgeBase.getInstance(context, "dbpedia");

	// static KnowledgeBase dbpedia = null;

	public static ApplicationContext init() {
		WorkerServletWrapper.testing = true;
		return new WorkerServletWrapper().getApplicationContext();
	}

	public static WorkerServletWrapper getWorkerServletWrapper() {
		return new WorkerServletWrapper();
	}

	public static boolean checkLabels(SearchResultDTO d) {
		for (ExampleDTO ex : d.getMatching()) {
			if (ex.getLabel() == null)
				return false;
		}
		for (ExampleDTO ex : d.getNotMatching()) {
			if (ex.getLabel() == null)
				return false;
		}
		return true;
	}

	public static boolean checkComments(List<ExampleDTO> d) {
		for (ExampleDTO ex : d) {
			if (ex.getComment() == null)
				return false;
		}
		return true;
	}

	@Test
	public void test() {
		for (ISearch s : Util.tiger.getAvailableSearches()) {
			System.out.println(s.getSearchDescriptor());
		}

	}

}
